package com.xpc.rpc.provider.spring.config;

import com.xpc.rpc.provider.server.base.BaseServer;
import com.xpc.rpc.provider.spring.scanner.DubboServiceScanner;
import com.xpc.rpc.register.common.config.RegisterConfig;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
@EnableConfigurationProperties(RegisterConfig.class)
public class RpcProviderAutoConfiguration implements InitializingBean {

    @Resource
    private RegisterConfig registerConfig;

    @Override
    public void afterPropertiesSet() throws Exception {
        DubboServiceScanner dubboServiceScanner = new DubboServiceScanner();
        dubboServiceScanner.doScanDubboServiceByPackages(registerConfig);
        BaseServer baseServer = new BaseServer(registerConfig);
        baseServer.startNettyServer();
    }
}
